﻿//----------------------------------------------------------------------------------------------------
// Visual Node Editor is used in the Editor state for editing of node specific options
//----------------------------------------------------------------------------------------------------

package HG.Visual
{
	import HG.Visual.VisualNode;
	
	import flash.events.*;
	
	public class VisualNodeEditor extends VisualObject
	{
		var m_node:VisualNode;
		
		//----------------------------------------------------------------------------------------------------
		public function VisualNodeEditor()
		{
			Fader.addEventListener(MouseEvent.MOUSE_UP, OnFaderClick);
			Button_Apply.addEventListener(MouseEvent.MOUSE_UP, OnButton_ApplyClick);
			
			// encryption
			Encryption.Button_Next.addEventListener(MouseEvent.MOUSE_UP, OnEncryption_NextClick);
			Encryption.Button_Prev.addEventListener(MouseEvent.MOUSE_UP, OnEncryption_PrevClick);
		}
		
		//----------------------------------------------------------------------------------------------------
		public function SetNode(visNode:VisualNode)
		{
			SetVisible(true);
			
			m_node = visNode;
			
			TXT_ID.text = m_node.GetID().toString();;
			TXT_Type.text = m_node.GetType();
			Icon.gotoAndStop(m_node.GetType());
			
			Encryption.EncryptionIcon.SetValue(m_node.GetEncryptionKey());
		}
		
		//----------------------------------------------------------------------------------------------------
		private function OnFaderClick(evt:MouseEvent)
		{
			SetVisible(false);
		}
		
		//----------------------------------------------------------------------------------------------------
		// Encryption
		//----------------------------------------------------------------------------------------------------
		private function OnEncryption_NextClick(evt:MouseEvent)
		{
			var newKey = Encryption.EncryptionIcon.GetValue() + 1;
			
			if (newKey < 16)
				Encryption.EncryptionIcon.SetValue(newKey);
		}
		
		//----------------------------------------------------------------------------------------------------
		private function OnEncryption_PrevClick(evt:MouseEvent)
		{
			var newKey = Encryption.EncryptionIcon.GetValue() - 1;
			
			if (newKey >= 0)
				Encryption.EncryptionIcon.SetValue(newKey);
		}
		
		//----------------------------------------------------------------------------------------------------
		// Actions
		//----------------------------------------------------------------------------------------------------
		private function OnButton_ApplyClick(evt:MouseEvent)
		{
			//m_node.SetOwner(Player.TXT_Player.text);
			m_node.SetEncryptionKey(Encryption.EncryptionIcon.GetValue());
			SetVisible(false);
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}